<template>
  <div>
    <UploadExcel :on-success="handleSuccess"></UploadExcel>
  </div>
</template>

<script>
import { transExcel } from "@/utils/index";
import { importEmployees } from "@/api/employees";

export default {
  methods: {
    async importEmployees(data) {
      try {
        const res = await importEmployees(data);
        console.log(res);
        this.$message.success(res.message);
        this.$router.push("/employees");
      } catch (err) {
        this.$message.error(err.message);
      }
    },
    handleSuccess({ header, results }) {
      console.log(header, results);
      const res = transExcel(results);
      console.log(res);
      this.importEmployees(res);
    },
  },
};
</script>

<style>
</style>